﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>EYWeb开发平台</title>
    <link href="~/Content/css/framework-font.css" rel="stylesheet" />
    <link href="~/Content/css/framework-login.css" rel="stylesheet" />
    <script src="~/Content/js/jquery/jquery-2.1.1.min.js"></script>
    <script src="~/Content/js/cookie/jquery.cookie.js"></script>
    <script src="~/Content/js/md5/jquery.md5.js"></script>
</head>
<body >
    <div class="wrapper">
        <div class="container">
            @*<div class="logo">
                <i class="fa fa-modx"></i>
                <h1><span>EY</span>Web</h1>
            </div>*@
            <form class="form">
                <div class="row">
                    <input id="txtAccount" type="text" placeholder="用户名" value="admin" />
                    <i class="fa fa-user"></i>
                </div>
                <div class="row">
                    <input id="txtPass" type="password" placeholder="密码" value="0000" />
                    <i class="fa fa-key"></i>
                </div>
                <div class="row">
                    <input type="text" id="txtCode" maxlength="4" placeholder="验证码" style="width: 190px;float:left" value="5678" />
                    <div style="float:left;width:110px;height:25px;">
                        <img id="imgCode" class="authcode" src="~/Login/GetAuthCode" width="80" height="25" />
                    </div>
                </div>
                <div class="row">
                    <button id="btnLogin" type="button"><span>登录</span></button>
                </div>
            </form>
            <div class="login_tips"></div>


        </div>
    </div>

    <script type="text/javascript">

        $(function () {
            $('.wrapper').height($(window).height());
            $(".container").css("margin-top", ($(window).height() - $(".container").height()) / 2 - 50);
            $("#txtAccount").focus();

            var error = top.$.cookie("login_error");
            if (error != null) {
                switch (error) {
                    case 'Overdue':
                        fromMessage("登录已超时,请重新登录.")
                        break;
                    case 'OnLine':
                        fromMessage("你的账号已在其他地方登录.");
                        break;
                    case '-1':
                        fromMessage("未知错误,请重新登录.");
                        break;
                }
                top.$.cookie("login_error", "", { path: "/", expires: -1 });
            }

            document.onkeydown = function (e) {
                if (!e) e = window.event;
                if ((e.keyCode || e.which) == 13) {
                    $("#btnLogin").trigger("click");
                }
            }

        })

        //点击图片更换验证码
        $("#imgCode").click(function () {
            $(this).attr("src", "/Login/GetAuthCode?time=" + Math.random());
        });

        $("#btnLogin").click(function () {
            login();
        });

        function login() {
            var $user = $("#txtAccount");
            var $pass = $("#txtPass");
            var $code = $("#txtCode");
            if ($user.val() == "") {
                fromMessage("请输入用户名.");
                $user.focus();
                return false;
            }
            if ($pass.val() == "") {
                fromMessage("请输入密码.");
                $pass.focus();
                return false;
            }
            if ($code.val() == "") {
                fromMessage("请输入验证码.");
                $code.focus();
                return false;
            }

            $("#btnLogin").attr("disabled", "disabled").find("span").html("Loading...");
            $.ajax({
                url: "/Login/CheckLogin",
                data: {
                    user: $.trim($user.val()),
                    pass:$.md5($.trim($pass.val())),
                    code: $.trim($code.val())
                },
                type: "post",
                dataType:"json",
                success: function (data) {
                    if (data.state == "success") {
                        $("#btnLogin").find("span").html("登录成功.");
                        window.setTimeout(function () {
                            window.location.href = "/Home/Index"
                        },1000);
                    }
                    else {
                        $("#btnLogin").removeAttr("disabled").find("span").html("登录");
                        fromMessage(data.message);
                        $code.val("");
                        $code.trigger("click");
                    }
                }

            });
            



        }





        //显示错误信息
        function fromMessage(msg) {
            $(".login_tips").find(".tips_msg").remove();
            $(".login_tips").append("<div class='tips_msg'><i class='fa fa- question - circle'></i>" + msg+"</div>");
        }

    </script>
</body>
</html>
